﻿//-----------------------------------------------------------------
//
// @(#)$Id: Download.aspx.cs,v 1.0 2013/12/16 9:55:09 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:55:09 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Web;

public partial class Download : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string fileName = Request["file"];
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            string downPath = Server.MapPath("~") + "\\DownLoad\\" + fileName;
            //路径         
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(downPath);
            if (!fileInfo.Exists)
                return;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=OutStockList.pdf");
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.Default;
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            fileInfo.Delete();

        }

    }
}
